#include "Camera.h"
#include "MyGL.h"

namespace Engine
{
	Camera::Camera(const Vec3& pos, const Vec3& upVector, const Vec3& foc,
		           float fov, float aspect, float nearPlane, float farPlane)
	{
		m_pos = pos;
		m_upVector = upVector;
		m_focus = foc;
		m_fov = fov;
		m_aspect = aspect;
		m_near = nearPlane;
		m_far = farPlane;
	}
	
	void Camera::SetLookAt(const Vec3& pos, const Vec3& upVector, const Vec3& foc)
	{
		m_pos = pos;
		m_upVector = upVector;
		m_focus = foc;
	}
	
	void Camera::SetPerspective(float fov, float aspect, float nearPlane, float farPlane)
	{
		m_fov = fov;
		m_aspect = aspect;
		m_near = nearPlane;
		m_far = farPlane;
	}
	
	void Camera::LookAt()
	{
		glMatrixMode(GL_MODELVIEW);
		glLoadIdentity(); 
	
		gluLookAt(     m_pos.x,      m_pos.y,      m_pos.z, 
			         m_focus.x,    m_focus.y,    m_focus.z,
				  m_upVector.x, m_upVector.y, m_upVector.z);
	}
	
	void Camera::Perspective()
	{
		glMatrixMode(GL_PROJECTION);
		glLoadIdentity();
	
		gluPerspective(m_fov, m_aspect, m_near, m_far);
	}

	void Camera::Update()
	{
		m_frustum.ReCalc();
	}
}